package com.example.demo.generator.config;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.HashMap;
import java.util.Map;

@Data
@ConfigurationProperties(prefix = "code-generator")
public class CodeGeneratorProperties {

    private TypeMapping typeMapping = new TypeMapping();
    private NamingStrategy namingStrategy = new NamingStrategy();
    private Cache cache = new Cache();

    @Data
    public static class TypeMapping {
        private Map<String, String> mappings = new HashMap<>();
        private String defaultType = "String";

        public TypeMapping() {
            // 默认类型映射
            mappings.put("bigint", "Long");
            mappings.put("int", "Integer");
            mappings.put("smallint", "Integer");
            mappings.put("tinyint", "Integer");
            mappings.put("mediumint", "Integer");
            mappings.put("serial", "Long");
            mappings.put("bigserial", "Long");
            mappings.put("decimal", "java.math.BigDecimal");
            mappings.put("numeric", "java.math.BigDecimal");
            mappings.put("double", "Double");
            mappings.put("float", "Float");
            mappings.put("date", "java.time.LocalDate");
            mappings.put("time", "java.time.LocalTime");
            mappings.put("timestamp", "java.time.LocalDateTime");
            mappings.put("datetime", "java.time.LocalDateTime");
            mappings.put("boolean", "Boolean");
            mappings.put("bool", "Boolean");
            mappings.put("bit", "Boolean");
            mappings.put("blob", "byte[]");
            mappings.put("binary", "byte[]");
            mappings.put("varbinary", "byte[]");
            mappings.put("text", "String");
            mappings.put("mediumtext", "String");
            mappings.put("longtext", "String");
            mappings.put("clob", "String");
            mappings.put("varchar", "String");
            mappings.put("char", "String");
            mappings.put("json", "String");
            mappings.put("enum", "String");
            mappings.put("set", "String");
            mappings.put("uuid", "String");
        }
    }

    @Data
    public static class NamingStrategy {
        private String defaultStrategy = "CamelCase";
        private boolean ignorePrefix = true;
        private String defaultPrefix = "sys_";
        private Map<String, String> caseStrategies = new HashMap<>();

        public NamingStrategy() {
            caseStrategies.put("CamelCase", "驼峰命名");
            caseStrategies.put("UnderScoreCase", "下划线命名");
            caseStrategies.put("UpperUnderScoreCase", "大写下划线命名");
        }
    }

    @Data
    public static class Cache {
        private boolean enabled = false;
        private int maxSize = 100;
        private long expireMinutes = 30;
    }
}